--- title: "最小消耗" created: 2025-11-28 tags: - 算法 --- # 最小消耗 ## 题目 [最小消耗](https://www.acwing.com/problem/content/3773/) ![[faa2820fff1d7734113a4723542ae987-faa2820f.png]] ## 思路分析 ![[dc3a3379009e9903c5b6281375eab6f1_720-34bdad8d.png]] ## 代码实现 ```cpp #include using namespace std; #define endl '\n' int main(){ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); int T;cin>>T; while(T--){ int n,a,b,c;cin>>n>>a>>b>>c; string str;cin>>str; int total=0; for(auto ch:str){ if(ch=='0') total+=min(a,b+c); else if(ch=='1') total+=min(b,a+c); } cout<